package com.yunke.controller.user;

import com.yunke.common.result.YunkeResult;
import com.yunke.entity.YunkeTag;
import com.yunke.service.YunkeTagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户端标签管理控制器
 * 
 * @author yunke
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/user/tag")
@RequiredArgsConstructor
@Tag(name = "用户端标签管理", description = "用户端标签管理相关接口")
public class UserTagController {

    private final YunkeTagService yunkeTagService;

    @GetMapping("/list")
    @Operation(summary = "查询标签列表")
    public YunkeResult<List<YunkeTag>> getTagList(
            @RequestParam(required = false) Integer tagType,
            @RequestParam(required = false) String tagCategory) {
        List<YunkeTag> tagList = yunkeTagService.getTagsByType(tagType, true);
        if (tagCategory != null) {
            tagList = yunkeTagService.getTagsByCategory(tagCategory, true);
        }
        return YunkeResult.success(tagList);
    }

    @GetMapping("/categories")
    @Operation(summary = "查询所有分类")
    public YunkeResult<List<String>> getAllCategories() {
        List<String> categories = yunkeTagService.getAllCategories();
        return YunkeResult.success(categories);
    }

    @GetMapping("/hot")
    @Operation(summary = "查询热门标签")
    public YunkeResult<List<YunkeTag>> getHotTags(
            @RequestParam(defaultValue = "20") Integer limit) {
        List<YunkeTag> hotTags = yunkeTagService.getHotTags(limit);
        return YunkeResult.success(hotTags);
    }

    @GetMapping("/recommend")
    @Operation(summary = "查询推荐标签")
    public YunkeResult<List<YunkeTag>> getRecommendTags(
            @RequestParam(defaultValue = "20") Integer limit) {
        List<YunkeTag> recommendTags = yunkeTagService.getRecommendTags(limit);
        return YunkeResult.success(recommendTags);
    }

    @GetMapping("/search")
    @Operation(summary = "搜索标签")
    public YunkeResult<List<YunkeTag>> searchTags(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "20") Integer limit) {
        List<YunkeTag> tags = yunkeTagService.searchTags(keyword, limit);
        return YunkeResult.success(tags);
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "查询标签详情")
    public YunkeResult<YunkeTag> getTagDetail(@PathVariable Long id) {
        YunkeTag tag = yunkeTagService.getTagById(id);
        if (tag == null) {
            return YunkeResult.error("标签不存在");
        }
        return YunkeResult.success(tag);
    }
} 